angular.module('Controller')
.controller('WFMainCtrl', ($scope, $rootScope,qygConfiguration,$localStorage,$http,userData,menuManage, $location)->
    $rootScope.navTabs={
        history:['welcome']
        active:'welcome',
        arrs:[{href:'welcome',icon:'fa-home',name:'',default:true}]
    }
    qygConfiguration.init()
    $scope.main = {
        brand: 'AdminerApp',
        name: 'Square Design'
    }
    $rootScope.chkSelected=(obj)->
        _.some(obj,(val,key)->val==true)
    $scope.admin = {
        layout: false,
        menu: false,
        fixedHeader: true,
        fixedSidebar: true,
        themeID: '24',
        navbarHeaderColor: 'bg-white',
        logo: 'bg-danger',
        asideColor: 'bg-dark'
    }
    $scope.color = {
        primary: '#248AAF',
        success: '#3CBC8D',
        info: '#29B7D3',
        purple: '#7266ba',
        warning: '#FAC552',
        danger: '#ED6D00'
    }
    $rootScope.goBack=(tabName)->
        if tabName!=undefined
            if _.some($rootScope.navTabs.history,(href)->href==tabName)
                $scope.clickTab(undefined ,tabName)
            else
                ''
        else
            len=$rootScope.navTabs.history.length
            preTab=$rootScope.navTabs.history[len-1] if len>0
            $scope.clickTab(undefined ,preTab)
    $scope.clickTab=(event,href)->
        if event
            event.preventDefault()
        if $rootScope.navTabs.active==href
            return
        $rootScope.navTabs.active=href
        $rootScope.navTabs.history=_.filter $rootScope.navTabs.history,(history)->history!=href
        $rootScope.navTabs.history.push href
#        console.log('clickTab.navTabs:',$rootScope.navTabs)
    $rootScope.closeCurrentPage=()->
        $scope.closeTab(undefined,$rootScope.navTabs.active)
    $scope.closeTab=(event,href)->
        if event
            event.preventDefault()
        $rootScope.navTabs.history=_.filter $rootScope.navTabs.history,(history)->history!=href
        $rootScope.navTabs.arrs=_.filter $rootScope.navTabs.arrs,(tab)->tab.href!=href
        if $rootScope.navTabs.active==href and $rootScope.navTabs.history.length>=1
            $rootScope.navTabs.active=$rootScope.navTabs.history[$rootScope.navTabs.history.length-1]
)



